package com.bjypc.youth.web.json;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.struts2.ServletActionContext;

import com.bjypc.youth.common.PageResult;
import com.bjypc.youth.common.QueryCriteria;
import com.bjypc.youth.dao.impl.ResearchArticleDaoImpl;
import com.bjypc.youth.entity.ResearchArticle;
import com.bjypc.youth.service.IResearchArticleService;
import com.googlecode.jsonplugin.annotations.JSON;
import com.opensymphony.xwork2.ActionSupport;

public class ResearchArticleAction extends ActionSupport {

	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = -6508572308233342943L;

	private IResearchArticleService researchArticleService;
	private List<ResearchArticle> articles = new ArrayList<ResearchArticle>();
	private boolean parseFile = false;
	private int totalCount;
	private int start;
	private int limit;
	/**
	 * status field to indicate whether operation succeeds
	 */
	private boolean success;
	private boolean failure;

	@Override
	public String execute() throws Exception {

		PageResult  result=this.researchArticleService.pageQuery(start,limit);
		this.totalCount=result.getTotalCount();
		this.articles=getArticleVO(result.getContent());
		return SUCCESS;
	}

	private List<ResearchArticle> getArticleVO(List content) {
		Iterator it=content.iterator();
		return ResearchArticleDaoImpl.getArticleVO(it);
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public boolean isFailure() {
		return failure;
	}

	public void setFailure(boolean failure) {
		this.failure = failure;
	}

	@JSON(serialize = false, deserialize = false)
	public IResearchArticleService getResearchArticleService() {
		return researchArticleService;
	}

	public void setResearchArticleService(
			IResearchArticleService researchArticleService) {
		this.researchArticleService = researchArticleService;
	}

	public List<ResearchArticle> getArticles() {
		return articles;
	}

	public void setArticles(List<ResearchArticle> articles) {
		this.articles = articles;
	}

	public boolean isParseFile() {
		return parseFile;
	}

	public void setParseFile(boolean parseFile) {
		this.parseFile = parseFile;
	}

	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}

	public int getStart() {
		return start;
	}

	public void setStart(int start) {
		this.start = start;
	}

	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

}
